package com.ht.medicaltreatment.view

import android.content.Context
import android.view.View
import androidx.lifecycle.viewModelScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.blankj.utilcode.util.ToastUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.ht.medicaltreatment.R
import com.ht.medicaltreatment.api.RetrofitUtils
import com.ht.medicaltreatment.bean.IceboxItemListBean
import com.ht.medicaltreatment.bean.ProjectBean
import com.xgst.driverlesscars.api.ApiService
import com.xgst.lib.http.ApiResult
import kotlinx.android.synthetic.main.dialog_item_list_layout.*
import kotlinx.android.synthetic.main.dialog_project_layout.*
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch

class CentrifugeProjectDialog(context: Context):BaseDialog(context,300f), OnItemClickListener {
    override fun getLayoutRes() = R.layout.dialog_item_list_layout
    private var adapter:ItemAdapter
    private var onClick:(String,Int)->Unit = {name,id -> }
    init {
        recyclerView.layoutManager = LinearLayoutManager(context)
        adapter = ItemAdapter()
        adapter.setOnItemClickListener(this)
        recyclerView.adapter = adapter
    }
    fun show(data:MutableList<IceboxItemListBean>, onClick:(String,Int)->Unit) {
        super.show()
        this.onClick = onClick
        adapter.setNewInstance(data)
    }

    override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
        val item = adapter.getItem(position) as IceboxItemListBean
        onClick(item.name,item.id)
        dismiss()
    }

    class ItemAdapter : BaseQuickAdapter<IceboxItemListBean, BaseViewHolder>(R.layout.item_list_layout){
        override fun convert(holder: BaseViewHolder, item: IceboxItemListBean) {
            val line = holder.getView<View>(R.id.line)
            if(getItemPosition(item) == 0){
                line.visibility = View.GONE
            }else{
                line.visibility = View.VISIBLE
            }
            holder.setText(R.id.tvName,item.name)
        }
    }
}
